//
//  NotificationController.swift
//  SecretChat
//
//  Created by TimTiger on 16/6/21.
//  Copyright © 2016年 TimTiger. All rights reserved.
//

import UIKit
import MudFramework

/// 通知管理
class NotificationController: NSObject {
    
    //注册推送
    class func registerRemoteNotification() {
        let application: UIApplication = UIApplication.sharedApplication()
        application.applicationIconBadgeNumber = 0
        //iOS8+ register APNS
        let notificationTypes: UIUserNotificationType  = [UIUserNotificationType.Badge, UIUserNotificationType.Sound, UIUserNotificationType.Alert];
        let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes:notificationTypes,categories:nil)
        application.registerUserNotificationSettings(settings)
    }
    
    //存储推送Token
    class func bindToken(deviceToken: NSData) {
        let pushToken = deviceToken.description.stringByReplacingOccurrencesOfString("<", withString: "").stringByReplacingOccurrencesOfString(">", withString: "").stringByReplacingOccurrencesOfString(" ", withString: "")
        MudUserDefaults.standardUserDefaults().setObject(pushToken, forKey:"pushToken")
        AccountController.shareController().updateCurrentUser()
    }
    
    //获取Token
    class func pushToken()->String? {
        return MudUserDefaults.standardUserDefaults().stringForKey("pushToken")
    }
}
